var test = '<div id="sexChange">'+
				'<div class="div-sex-border-top">'+
					'<div class="div-item-sex" data-lity-close="" onclick="changeSex(1)">男</div>'+
					'<div class="div-item-sex div-top-border" data-lity-close="" onclick="changeSex(0)">女</div>'+
				'</div>'+
				'<div class="sex-opacity"></div>'+
				'<button type="button"  onclick="cancelSex()" class="div-sex-border-down div-item-sex">取消</button>'+
		    '</div>';


function changeSexLayer() {
	layer.open({
	    content: test,
	     style: 'width: 100%;background: transparent;'
	});
}

function cancelSex() {
	layer.closeAll();
}

function changeSex (sex) {
	$('#sexValue').html((sex==1?"男":"女"));
	layer.closeAll();
}

function changeAddress() {	
	nextView("changeAddress.html");
}

var picUuid="";
function changeHead(isInit) {
	$('#uploadphoto').localResizeIMG({
      width: 60,
      quality: 1,
      success: function (result) {  
    	var submitData={
			"fileName":"a123.png","imgData":result.clearBase64,"cratmType":1, "cratmDir":"jgj/head", 
		};
		$('#img_head_pic').css("background","url(" + result.base64 + ")  no-repeat"); 
		$.ajax({
		   type: "POST",
		   url: urlfile + "coreAttachment/upload/stream",
		   data: submitData,
		   dataType:"json",
		   success: function(data){
			   	if(!data.success) {
					alert(data.errMsg);
				}else{
				   $('#loading').css("display","none");
				   picUuid = data.data;
				}
		   }, 
			complete :function(XMLHttpRequest, textStatus){
				$('#loading').css("display","none");
			},
			error:function(XMLHttpRequest, textStatus, errorThrown){ //上传失败 
			   $('#loading').css("display","none");
			   alert(XMLHttpRequest.status);
			   alert(XMLHttpRequest.readyState);
			   alert(textStatus);
			}
		}); 
      }
    });
}


$(function(){
	//初始化
	changeHead(true);

	$('#infoName').val(dataGet("userName"));
	$('#sexValue').html((dataGet("userSex")==1?"男":"女"));
	$('#myAddress').html(dataGet("userAddress")=="undefined"?"请完善地址" : dataGet("userAddress"));
	$('#birth').val(dataGet("userBirthday")=="undefined"?"请完善出生年月" : dataGet("userBirthday"));
	$('#phoneNumber').html(dataGet("userPhone"));

	if(dataGet("headUuid")) {
		$('#img_head_pic').css("background","url(" + urlfile + "coreAttachment/image/get/" + dataGet("headUuid") + ")  no-repeat");
	}
});

function changePersonInfo() {

	var crusrUuid = dataGet("userUuid");
	var crusrName = $('#infoName').val();
	var crusrGender = $('#sexValue').html()=="男"?1:0;
	var crusrAddress = $('#myAddress').html();
	var crusrBirthday = $('#birth').val();
	var crusrMobile = $('#phoneNumber').html();


	var data = "&crusrUuid="+crusrUuid + "&crusrName="+crusrName + "&crusrGender="+crusrGender+ "&crusrAddress="+crusrAddress
				+ "&crusrBirthday="+crusrBirthday+ "&crusrMobile="+crusrMobile + "&crusrType="+1;
	if(picUuid!="") {
		data += "&uuids="+picUuid;
	}
	var url = urlfile + "coreUser/update/user";

	ajaxTool("post",data,url,
		function error(XMLHttpRequest, textStatus, errorThrown,fnErr){
			alert("error:" + XMLHttpRequest);
		},
		function success(data){
			if(!data.success) {
				alert(data.errMsg);
			}else{
				dataSave("userName", $('#infoName').val());
				nextView("personIndex.html");
			}
		}
	);
}